package com.wealth.scsj.b_app.model;




import com.wealth.scsj.b_app.base.AboutAddNewGoodsBase;
import com.wealth.scsj.b_app.base.UserEvaluateBase;
import com.wealth.scsj.b_app.bean.AllClassfyBean;
import com.wealth.scsj.b_app.bean.BaseBean;
import com.wealth.scsj.b_app.bean.GetEvaluationNumBean;
import com.wealth.scsj.b_app.bean.GoodsDetailBean;
import com.wealth.scsj.b_app.bean.QueryAllMarksBean;
import com.wealth.scsj.b_app.bean.QueryAllTerraceBean;
import com.wealth.scsj.b_app.bean.QueryShopBrandBean;
import com.wealth.scsj.b_app.bean.UserEvaluateListBean;

import dkmvp.net.ResponseCallback;
import dkmvp.net.ResponseHandler;
import dkmvp.net.RetryWithDelay;
import okhttp3.RequestBody;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 修改登录密码Model
 */

public class AboutAddNewShopsModel extends BaseModel implements AboutAddNewGoodsBase.IModel {


    @Override
    public Subscription getShopBrandData(RequestBody requestBody, final ResponseCallback<QueryShopBrandBean> callback) {
        Observable<QueryShopBrandBean> observable = service.queryShopBrands(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<QueryShopBrandBean>() {
                    @Override
                    public void call(QueryShopBrandBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }

    @Override
    public Subscription getAllMarksData(RequestBody requestBody, final ResponseCallback<QueryAllMarksBean> callback) {
        Observable<QueryAllMarksBean> observable = service.queryAllMarks(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<QueryAllMarksBean>() {
                    @Override
                    public void call(QueryAllMarksBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }

    @Override
    public Subscription getAllClassfyData(RequestBody requestBody, final ResponseCallback<AllClassfyBean> callback) {
        Observable<AllClassfyBean> observable = service.queryAllclassify(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<AllClassfyBean>() {
                    @Override
                    public void call(AllClassfyBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }

    @Override
    public Subscription getAllTerraceData(RequestBody requestBody, final ResponseCallback<QueryAllTerraceBean> callback) {
        Observable<QueryAllTerraceBean> observable = service.queryAllTerrace(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<QueryAllTerraceBean>() {
                    @Override
                    public void call(QueryAllTerraceBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }

    @Override
    public Subscription getAllGoodsData(RequestBody requestBody, final ResponseCallback<GoodsDetailBean> callback) {
        Observable<GoodsDetailBean> observable = service.queryAllGoods(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<GoodsDetailBean>() {
                    @Override
                    public void call(GoodsDetailBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }
}
